package utils

import (
	"math/rand"
	"reflect"
	"strconv"
)

func CheckErr(e error) bool {
	if e != nil {
		panic(e)
	} else {
		return true
	}
}

func IsEmpty(a interface{}) bool {
	v := reflect.ValueOf(a)
	if v.Kind() == reflect.Ptr {
		v = v.Elem()
	}
	return v.Interface() == reflect.Zero(v.Type()).Interface()
}

func IsNotEmpty(a interface{}) bool {
	return !IsEmpty(a)
}

func GenerateRandomStr(strLen int) string {
	resStr := ""
	for i := 0; i < strLen; i++ {
		resStr += string(rune(rand.Int63n(26) + 65))
	}
	return resStr
}

func ParseInt(target string) int {
	if numb, err := strconv.Atoi(target); err == nil {
		return numb
	} else {
		panic("Convert String to Int Failed.\n")
	}
}

func ParseBool(target string) bool {
	if boolean, err := strconv.ParseBool(target); err == nil {
		return boolean
	} else {
		panic("Convert String to Boolean Failed.\n")
	}
}
